﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Collections.ObjectModel;
using MOJsdk;

namespace MOJ
{
    /// <summary>
    /// Interaction logic for Control_SelectLanguage.xaml
    /// </summary>
    public partial class Control_SelectLanguage : UserControl
    {
        public Control_SelectLanguage()
        {
            InitializeComponent();
            INI();
        }

        private ObservableCollection<ISO639_1> _langs;

        #region Inicialization
        private void INI()
        {
            FillLanguages();
            INIEvents();
            INIStyle();
        }

        private void INIEvents()
        {
            OnSelectLanguage += delegate { };
            _listView.SelectionChanged += Select;
        }
        private void INIStyle()
        {
            _Grid.ApplyStyle("0101103");
            _listView.ApplyStyle("0101104");
        }
        private void FillLanguages()
        {
            _langs = new ObservableCollection<ISO639_1>(ISO639_1.LoadLanguages().OrderBy(z=>z.Country));
            _listView.ItemsSource = _langs;
        }
        #endregion

        private void Select(object sender, SelectionChangedEventArgs e)
        {
            int x = _listView.SelectedIndex;
            if (x == -1) return;

            OnSelectLanguage(_langs[x]);
        }

        public delegate void SelectLanguage(ISO639_1 Language);
        public event SelectLanguage OnSelectLanguage;
    }
}
